# Build recipe for squashfs-tools.
#
# Copyright (c) 2021, 2023 Matias Fonzo, <selk@dragora.org>.
# Copyright (c) 2022 DustDFG, <dfgdust@gmail.com>.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Exit immediately on any error
set -e

program=squashfs-tools
version=20230406_cbaa34a
release=1

# Define a category for the output of the package name
pkgcategory=tools

tarname=${program}-${version}.tar.lz

# Remote source(s)
#fetch=https://downloads.sourceforge.net/project/squashfs/squashfs/squashfs${version}/$tarname
fetch="
 https://dragora.mirror.garr.it/current/sources/$tarname
 rsync://rsync.dragora.org/current/sources/$tarname
"

description="
Tools to create and extract Squashfs filesystems.

This is a squashed read-only filesystem for GNU/Linux.
"

homepage=https://github.com/plougher/squashfs-tools/
license=GPLv2+

# Source documentation
docs="
  ACKNOWLEDGEMENTS ACTIONS-README CHANGES COPYING README* USAGE
  RELEASE-READMEs/DONATIONS
"
docsdir="${docdir}/${program}-${version}"

build()
{
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    # Apply a patch to include LZIP support
    patch -p1 < "${worktree}/patches/squashfs-tools/squashfs-tools-20221209_c901403_lzip-0.diff"

    # Set sane permissions
    chmod -R u+w,go-w,a+rX-s .

    cd squashfs-tools

    make -j${jobs} CC=cc EXTRA_CFLAGS="$QICFLAGS -O3" LDFLAGS="$QILDFLAGS" \
     GZIP_SUPPORT=1 \
     LZIP_SUPPORT=1 \
     XZ_SUPPORT=1 \
     LZO_SUPPORT=1 \
     LZ4_SUPPORT=0 \
     ZSTD_SUPPORT=1 \
     COMP_DEFAULT=lzip \
     XATTR_SUPPORT=1 \
     install INSTALL_DIR="${destdir}/usr/bin"

    cd ../

    # Copy documentation
    mkdir -p "${destdir}/$docsdir"
    cp -p $docs "${destdir}/$docsdir"
}

